package functions 
{	import functions.FunctionNode;
	/**	 * @author pbalogh	 */	public class SetPixel extends FunctionNode 
	{		public function SetPixel()
		{
			funcname = "setpixel";
			functiontype = FUNCTION;		}
		
		override public function getValue( args:XML, scope:Object ) : XML
		{
			var returnXML:XML = <list/>;
//			trace("In setpixel, raw args are " + args.toXMLString());
			var literals:Array = new Array();
			
			for( var i : int = 0;i < args.children().length(); i++)
			{
				literals.push( Evaluator.getLiteral(Evaluator.evaluate(args.children()[ i ], scope)) );
			}
			
			trace("literals = " + literals); 
			
			// we received x, y, r, g, b
			
			var r : int = Math.floor( literals[2] );
			var g : int = Math.floor( literals[3] );
			var b : int = Math.floor( literals[4] );
			
			var color : Number =  	( r << 16 ) |
									( g << 8  ) |
									b;
			
			Evaluator.getInstance().bmd.setPixel( literals[0], literals[1], color );
			trace("Setting pixel color to " + color.toString( 16 ) );
			return returnXML;		
		}
	}}